const express = require('express')
const router = express.Router()

// 导入站村推荐的处理函数模块
const recommend_handler = require('../router_handler/recommend')



// 导入解析 formdata 格式表单数据的包
const multer = require('multer')
// 导入处理路径的核心模块
const path = require('path')
// 创建 multer 的实例对象，通过 dest 属性指定文件的存放路径

// 设置存储引擎
const storage = multer.diskStorage({
    destination: function (req, file, cb) {
      cb(null, 'uploads/recommend/');
    },
    filename: function (req, file, cb) {
      // cb(null, file.fieldname + '-'  + Date.now() + path.extname(file.originalname));
      cb(null, req.body.title + '-'  + Date.now() + path.extname(file.originalname));
    }
  });
  
  // 创建上传对象
  const upload = multer({ storage: storage });

// 1. 导入验证表单数据的中间件
const expressJoi = require('@escook/express-joi')
// 2. 导入需要的验证规则对象
const { get_recommend_schema, update_recommend_schema } = require('../schema/recommend')

// 获取推荐信息
router.get('/getrecommend/:userId',  recommend_handler.getRecommend)
//根据ID
// router.get('/getrecommend/:id',  expressJoi(get_recommend_schema), recommend_handler.getRecommendById)


// 编辑站村推荐的基本信息
router.post('/updaterecommend', upload.single('logoImg'),  recommend_handler.editRecommend)

// 拖拽修改
router.post('/updateSortOrder/:userId',   recommend_handler.saveSortOrder)



module.exports = router